<template>
	<view>
		<cu-custom class="text-Black" bgColor="bg-red" :isBack="true"><block slot="backText"></block>
			<block slot="content">报单进度</block>
		</cu-custom>
		<view class="space-between bg-white">
			<scroll-view scroll-x class="bg-white nav solid-bottom">
				<view class="flex text-center">
					<view class="cu-item flex-sub " :class="index==TabCur?'cur text-'+theme:''" v-for="(item,index) in tabs" :key="index"
					 @tap="tabSelect" :data-id="index">
						{{item.name}}
					</view>
				</view>
			</scroll-view>
		</view>
		<view class="">
			<view class="" v-for="(tab, i) in tabs" v-if="i==TabCur" :key="i">
				<view class="cu-list" v-for="(item,index) in tab.list" :key="index">
					<view class="bg-white margin-top shadow margin-lr radius">
						<view class="space-between padding-sm solid-bottom  ">
							<view class="content">
								<view class="text-lg">{{item.realname}}</view>
								<view class="cu-tag margin-top-xs  sm round bg-orange">{{item.level.name}}</view>
							</view>
							<view class="action text-right">
								<view class="cu-tag">{{item.province?item.province.title:''}} {{item.city?item.city.title:''}}</view>
								<view class="margin-top-xs">{{item.mobile}}</view>
							</view>
						</view>
						<view class="space-between padding-sm align-center">
							<view>
								<text v-if="i==0">报单时间：{{$common.timeFormat(item.created_at)}}</text>
								<text v-else-if="i==1">审核时间：{{$common.timeFormat(item.examine_time)}}</text>
								<text v-else>原因：{{item.reason}}</text>
							</view>
							<view class="cu-btn sm round" :class="'line-'+theme" @tap="goPage('/pages/channel/apply_detail?id=' + item.id)">详情</view>
						</view>
					</view>

				</view>
				<view class="cu-load margin-center" :class="tab.loading?'loading':'over'"></view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				TabCur: 0,
				CLOUDPATH: this.$config.cloudPath,
				theme: this.$config.THEME(),
				tabs: [{
					name: "审核中",
					type: 0,
					list: [],
					page: 1,
					hasMore: true,
					loading: false
				}, {
					name: "已通过",
					type: 1,
					list: [],
					page: 1,
					hasMore: true,
					loading: false
				}, {
					name: "驳回",
					type: 2,
					list: [],
					page: 1,
					hasMore: true,
					loading: false
				}],
			}
		},
		onLoad() {
			if (this.$common.loginAuth(true)) {
				this.getList(this.TabCur)
			}
		},
		onShow() {
			this.$common.loginAuth(true)
		},
		methods: {
			tabSelect(e) {
				if (this.TabCur != e.currentTarget.dataset.id) {
					this.TabCur = parseInt(e.currentTarget.dataset.id)
					this.getList(this.TabCur)
				}
			},
			getList(index) {
				let obj = this.tabs[index]
				if (obj.hasMore && !obj.loading) {
					this.tabs[index].loading = true
					this.$http
						.get('channel_apply_index', {
							type: obj.type,
							page: obj.page
						})
						.then((response) => {
							console.log(response)
							let list = obj.list
							if (response.data.data.length > 0) {
								list = list.concat(response.data.data)
							} else {
								this.tabs[index].hasMore = false
							}
							this.tabs[index].list = list
							this.tabs[index].loading = false
							this.tabs[index].page += 1
						})
						.catch((response) => {
							console.log(response)
							this.tabs[index].loading = false
						})
				}

			}
		},
	}
</script>

<style>
</style>
